﻿package app.view.components.header 
{
	import app.model.types.LangTypes;
	import app.model.types.SectionType;
	import app.view.events.UIEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.ui.Mouse;
	import flash.utils.Dictionary;
	import flash.utils.Timer;
	import org.casalib.util.DateUtil;
	
	/**
	 * Заголовок сайта,
	 * содержит лого, 3 кнопки
	 * @author firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class SiteHeaderBase extends Sprite
	{
		public var logo:Sprite;
		public var time:TimeDisplay;
		public var date:DateDisplay;
		public var langs:LangsBar;
		// идентификатор текущей открытой секции
		public var sectionID:String;
		private var _timer:Timer;
		private var _date:Date;
		
		private var _dictionary:Dictionary;
		
		public function SiteHeaderBase() 
		{
			super();
			init();
		};
		private function init():void
		{
			_dictionary = new  Dictionary();
			_dictionary[LangTypes.RUSSIAN] = { today:'Сегодня', monday: 'Понедельник', 
			tuesday: 'Вторник', wednesday:'Среда', thursday: 'Четверг', 
			friday: 'Пятница', saturday: 'Суббота',  sunday:'Воскресенье',
			january: 'Января', february: 'Февраля', march : 'Марта', april: 'Апреля', may:'Мая',
			june:'Июня', july:'Июля', august:'Августа', september:'Сентября', october:'Октября'};
			
			//, 'June', 'July', 'August', 'September', 'October',
			
			_dictionary[LangTypes.ENGLISH] = { today:'Today', monday: 'Monday', 
			tuesday: 'Tuesday', wednesday:'Wednesday', thursday: 'Thursday', 
			friday: 'Friday', saturday: 'Saturday',  sunday:'Sunday', 
			january: 'January', february: 'February', march : 'March', april: 'April', may:'May',
			june:'June', july:'July', august:'August', september:'September', october:'October'};
			
			_dictionary[LangTypes.CHINA] = { today:'Today', monday: 'Monday', tuesday: 'Tuesday', wednesday:'Wednesday', thursday: 'Thursday', friday: 'Friday', 
			saturday: 'Saturday',  sunday:'Sunday',
			january: 'January', february: 'February', march : 'March', april: 'April', may:'May',
			june:'June', july:'July', august:'August', september:'September', october:'October'};
			
			
			_timer = new Timer(1000);
			_timer.addEventListener(TimerEvent.TIMER, onTimer);
			_timer.start();
			onTimer();
			langs.addEventListener(Event.CHANGE, onLangChange);
			
			addEventListener(MouseEvent.ROLL_OVER, onOver);
			addEventListener(MouseEvent.ROLL_OUT, onOut);
		};
		
		private function onOut(event:MouseEvent):void 
		{
			if( sectionID != SectionType.PAGE_MAIN) return
			Mouse.hide();
		};
		
		private function onOver(event:MouseEvent):void 
		{
			//if( sectionID != SectionType.PAGE_MAIN) return
			Mouse.show();
		};
		
		private function onLangChange(event:Event):void 
		{
			////trace('onLangChange : '  + langs.lang);
			onTimer();
			dispatchEvent ( new UIEvent ( UIEvent.LANG_CHANGE, false, false , langs.lang));
		};
		
		private function onTimer(event:TimerEvent = null):void 
		{
			_date = new Date();
			
			var minute:String;
			_date.getMinutes() < 10 ? minute = String('0' + _date.getMinutes()) : minute = String(_date.getMinutes());
			
			time.textField.text = _date.getHours() + ':' + minute;
			////trace(_date.getSeconds());
			var today:String = _dictionary[langs.lang].today;
			var day:String = _dictionary[langs.lang][DateUtil.getDayAsString(_date.getDay()).toLowerCase()];
			var month:String = _dictionary[langs.lang][DateUtil.getMonthAsString(_date.getMonth()).toLowerCase()]
			////trace(_dictionary[langs.lang], langs.lang,  day);
			//date.textField.text = today +  '\n' + _date.getDate() + ' ' + month +  '\n' + day;
			date.textField.text = _date.getDate() +  ' ' + month;
		};
		
		
		
	};
};